@layout("/common/default.html",{title:'添加',libs:['form']}){
    <!--form表单-->
    <form class="layui-form"  lay-filter="layui-form-office" id="layui-form-office">
        <input type="hidden" id="onlyid" name="id" value="${office.id!}">
        <input type="hidden" id="op" name="op" value="${office.op!}">

        <div class="layui-fluid">
            <div class="layui-card">

                <div class="layui-card-body">
                    <div class="layui-form-item layui-row">


                        <div class="layui-inline layui-col-md9" id="superior" style="display: none">
                            <label class="layui-form-label layui-required">上级部门</label>
                            <input type="hidden" id="parentid" value="${office.parent.id!}">
                            <div class="layui-input-block">
                                <input type="text" id="parent" name="parent.id"  placeholder="请输入" autocomplete="off" class="layui-input" >
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label layui-required">部门名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name"  value="${office.name!}" lay-verify="required" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">所属区域<span style="color: red;">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" id="area" name="area.id"  placeholder="请输入" autocomplete="off" class="layui-input" >
                            </div>
                        </div>



                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">部门编码</label>
                            <div class="layui-input-block">
                                <input type="text" id="code" name="code" value="${office.code!}" lay-verify="" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">部门类型</label>
                            <div class="layui-input-block">
                                <#select path="type" value="${office.type!}" items="${fnc.getDictList('sys_office_type')}"/>
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">联系地址</label>
                            <div class="layui-input-block">
                                <input type="text" id="address" name="address" value="${office.address!}" lay-verify="" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>



                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">部门等级</label>
                            <div class="layui-input-block">
                                <#select path="grade" value="${office.grade!}" items="${fnc.getDictList('sys_office_grade')}"/>
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">邮政编码</label>
                            <div class="layui-input-block">

                                <input type="text" id="zipCode" name="zipCode" value="${office.zipCode!}" lay-verify="" placeholder="请输入"
                                       autocomplete="off" class="layui-input">

                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">负责人</label>
                            <div class="layui-input-block">
                                <input type="text" id="master" name="master"  value="${office.master!}" lay-verify="" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9" >
                            <label class="layui-form-label" >是否可用</label>
                            <div class="layui-input-block">
                                <input type="radio" name="useable" value="1" title="是" lay-filter="flag" checked><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>是</div></div>
                                <input type="radio" name="useable" value="0" title="否" lay-filter="flag"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>否</div></div>
                            </div>
                        </div>


                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="text" id="sort" name="sort"  value="${office.sort!}" lay-verify="required" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>


                    </div>
                </div>
            </div>

        </div>
        <div class="form-group-bottom" style="z-index: 200" align="center">
            <button class="layui-btn" lay-filter="btnSubmit" lay-submit>&emsp;提交&emsp;</button>
            <button   id="btnclose" class="layui-btn layui-btn-primary"  >&emsp;取消&emsp;</button>
        </div>

    </form>
<!--js逻辑-->
<script>
    layui.use(['form', 'submitform', 'treeSelect'], function () {
        var $ = layui.$,
            form = layui.form,
            submitform = layui.submitform,
            treeSelect = layui.treeSelect;

            var parentid=$("#parentid").val();
            if(parentid!=''){
                $("#superior").css("display","block");
            }

            treeSelect.render({
                elem: '#parent',
                title: '上级菜单',
                url: '/sys/office/treeData',
                icon: 'layui-icon layui-icon-app',
                value: '${office.parent.id!}',
                label: '${office.parent.name!}'
            });


        //为表单付出始值
        form.val('layui-form-office', {
            "useable":'${office.useable}',
        });

            treeSelect.render({
                elem: '#area',
                title: '所属区域',
                url: '/sys/area/treeData',
                icon: 'layui-icon layui-icon-app',
                value: '${office.area.id}',
                label: '${office.area.name}'
            });




        form.on("submit(btnSubmit)", function (data) {
            var field=data.field;

            // 请求后台
            submitform.form('/sys/office/save',field);
            return false;
        });



    });
</script>

@}
